home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / 3dvect37.zip / STARS.ASM < prev    next >
Assembly Source File  |  1994-06-22  |  11KB  |  391 lines

  1. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  2. ;
  3. ; Filename     : STARS.ASM
  4. ; Included from: Main assembley module
  5. ; Description  : Font and cosmetic screen handling routines.
  6. ;                This basically draws backgound screens/opening menus.
  7. ;                Have you played Red Baron or Aces of the Pacific?  It's
  8. ;                kind of like that.
  9. ;
  10. ; Written by: John McCarthy
  11. ;             1316 Redwood Lane
  12. ;             Pickering, Ontario.
  13. ;             Canada, Earth, Milky Way (for those out-of-towners)
  14. ;             L1X 1C5
  15. ;
  16. ; Internet/Usenet:  BRIAN.MCCARTHY@CANREM.COM
  17. ;         Fidonet:  Brian McCarthy 1:229/15
  18. ;   RIME/Relaynet: ->CRS
  19. ;
  20. ; Home phone, (905) 831-1944, don't call at 2 am eh!
  21. ;
  22. ; Send me your protected mode source code!
  23. ; Send me your Objects!
  24. ; But most of all, Send me a postcard!!!!
  25. ;
  26. ; Display backgound stars, 1024 stars.  Routine is  designed  so   only  stars
  27. ; which will be on the  screen  are  calculated.   This  is  first  done  with
  28. ; x angle indexing, then with y angle clipping, then with z distance clipping.
  29. ; this way, stars which most likely wont be visable are not rotated with those
  30. ; time-consuming IMUL's.  a mode has also been added to  make  non-perfect  3d
  31. ; stars.  this mode requires that the constants xstar  and ystar  be  adjusted
  32. ; by the user the make the stars "look" the same as perfectly calculated stars
  33. ; however, when these values are adjusted correctly, this routine is about 40%
  34. ; faster. this can be done because the stars are at a constant  distance  from
  35. ; the camera.
  36. ;░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
  37.  
  38.          .386p
  39.          jumps
  40.  
  41. code32   segment para public use32
  42.          assume cs:code32, ds:code32
  43.  
  44.          include pmode.ext       ; protected mode externals
  45.          include xmode.ext       ; include externals for xmode routines
  46.          include 3d.ext
  47.          include equ.inc         ; every .asm should have access to this stuff
  48.          include macros.inc
  49.  
  50.          include stardata.inc
  51.  
  52.          public show_stars
  53.          public starcolour
  54.  
  55. ; angle tolerence (lower untill stars get clipped)
  56. largest         equ 150 ; this is good without using z rotations in 320x400
  57.  
  58. ; this is only used when perfect_stars = yes
  59. zdistance       equ 14500 ; z clipping parameter, 16384 = all stars clipped
  60.  
  61. xstar           equ ratiox*4/128 ; these are divided by 4 to give decimals.
  62. ystar           equ ratioy*4/128 ; used when perfect_stars=no
  63.  
  64. number_of_stars equ 1024         ; must be 2^some_number
  65. cut             equ 5
  66.  
  67.  
  68. ;use_half_stars equ no           ; both already defined in equ.inc
  69. ;perfect_stars  equ no           ; fast star calculation if no
  70.  
  71. smatrix       dd 6 dup (0)       ; star matrix, ematrix*xscale*yscale
  72. angle_count   dw 0
  73. starhalfpoint dw 512 ;400,600?   ; lower cutoff if use_half_stars = yes
  74. starcolour    dd 00c0d0e0fh      ; colours for 4 stars
  75.  
  76. we_is_out_of_here:
  77.          ret
  78.  
  79. show_stars:
  80.          mov si,eyeax            ; get camera x angle
  81.          add esi,16384           ; 1/4 quadrant
  82.          shr esi,5               ; 32768/2^5 = 1024
  83.          and esi,000007ffh
  84.  
  85.          mov ebp,esi
  86.          add ebp,largest         ; sweep to bottom
  87.          sub esi,largest         ; start from top
  88.  
  89.          cmp ebp,number_of_stars-cut
  90.          jle s okmax
  91.          mov ebp,number_of_stars-cut
  92. okmax:
  93.          cmp esi,cut
  94.          jge s ok_min
  95.          mov esi,cut             ; looking almost directly up
  96. ok_min:
  97.          movzx esi,xn1[esi]
  98.          movzx ebp,xn1[ebp]
  99.  
  100.          mov eax,ebp
  101.          sub eax,esi
  102.          shl eax,2
  103.          mov angle_count,ax
  104.  
  105.          shl esi,2
  106.  
  107.         ;mov angle_count,number_of_stars
  108.         ;mov esi,0               ; uncomment this!! (along with stuff below)
  109.  
  110.          if use_half_stars eq yes
  111.          cmp esi,starhalfpoint
  112.          jae s we_is_out_of_here
  113.          endif
  114.  
  115.          call set_star_matrix    ; pre-cal star matrix
  116.  
  117. more_stars:
  118.          mov al,sya[esi]       ; star_y_angle
  119.          neg al
  120.          sub al,byte ptr eyeay+1
  121.  
  122.          mov bl,tol[esi]         ; bx = tol *256
  123.          mov cl,bl
  124.  
  125.          shr cl,1
  126.          movsx ecx,cl
  127.          add al,cl
  128.  
  129.          cmp al,bl
  130.          ja  skipit               ; try removing these skipit jumps!!!
  131. doit:
  132.          push esi
  133.  
  134.          movsx ebx,sxl[esi]      ; star_x_location
  135.          movsx ecx,syl[esi]
  136.          movsx ebp,szl[esi]
  137.  
  138.          if perfect_stars eq yes
  139.          shl ebx,7               ; * for some accuracy
  140.          shl ecx,7
  141.          shl ebp,7
  142.  
  143.          call srotatez           ; star is eligable, calculate actual screen loc
  144.  
  145.         ;add esi,35000           ; try this too! (this is the best part)
  146.  
  147.          cmp esi,zdistance       ; clip if too close (not on apex of sphere)
  148.          jl abort_s
  149.          endif
  150.  
  151.          call srotatex           ; check tolerence in parts (saves imul's)
  152.  
  153.          if perfect_stars eq yes
  154.          mov eax,edi             ; some code from make3d routine (math.inc)
  155.          cdq
  156.          idiv esi                ; if fast mode selected, avoid idiv's
  157.          mov edi,eax
  158.          endif
  159.  
  160.          cmp di,xmins            ; draw single point/bullet
  161.          jl s abort_s
  162.          cmp di,xmaxs
  163.          jge s abort_s
  164.  
  165.          call srotatey           ; x is ok, solve for y
  166.  
  167.          if perfect_stars eq yes
  168.          mov eax,ecx
  169.          cdq
  170.          idiv ebp
  171.          mov ecx,eax
  172.          endif
  173.  
  174.          cmp cx,ymins
  175.          jl s abort_s
  176.          cmp cx,ymaxs            ; ymaxs1 if larger star (for high res screens)
  177.          jge abort_s
  178.  
  179.          mov edi, current_page   ; point to active vga page
  180.          add bx,xcent
  181.          add cx,ycent
  182.  
  183.          movzx esi,cx
  184.          mov eax,[esi*4+fastimultable] ; get offset to start of line
  185.  
  186.          mov cl, bl              ; copy to extract plane # from
  187.          shr bx, 2               ; x offset (bytes) = xpos/4
  188.          add ebx, eax            ; offset = width*ypos + xpos/4
  189.  
  190.          mov ax, map_mask_plane1 ; map mask & plane select register
  191.          and cl, plane_bits      ; get plane bits
  192.          shl ah, cl              ; get plane select value
  193.          out_16 sc_index, ax     ; select plane
  194.  
  195.          pop eax                 ; select colour for star
  196.          push eax
  197.          and eax,3               ; four colours
  198.          mov al,byte ptr starcolour[eax]
  199.  
  200.          and ebx,0000ffffh
  201.          mov b [edi+ebx],al      ; draw pixel
  202. ;        add edi,xactual/4
  203. ;        mov b [edi+ebx],al      ; draw larger pixel
  204.  
  205. ; if drawing larger star, change above code to this!
  206. ;        cmp cx,ymaxs1
  207. ;        jge s abort_s
  208. abort_s:
  209.          pop esi
  210. skipit:
  211.          if use_half_stars eq yes
  212.          cmp si,starhalfpoint
  213.          jae outhandle
  214.  
  215.          else
  216.          cmp esi,number_of_stars-1-cut
  217.          jae s outhandle
  218.          endif
  219.  
  220.          inc esi
  221.          dec angle_count
  222.          jnz more_stars
  223.  
  224. outhandle:
  225.          if useborders eq yes
  226.          mov ax,xmin
  227.          mov bx,xmax
  228.          mov cx,ymin
  229.          mov dx,ymax
  230.  
  231.          dec ebx
  232.          dec edx
  233.  
  234.          mov lxupdate+0,ax
  235.          mov lxupdate+2,bx
  236.          mov lyupdate+0,cx
  237.          mov lyupdate+2,dx
  238.          endif
  239.  
  240.          ret
  241.  
  242. ; pre-multiply ematrix_row*constant_for_row
  243. ; to generate new matrix
  244.  
  245. ; this can be done because we don't have any
  246. ; camera location offsets (stars are at a
  247. ; fixed distance from the camera)
  248.  
  249.          align 16
  250.  
  251.          if perfect_stars eq yes
  252.  
  253. set_star_matrix:
  254.          mov ebx,ematrix+0
  255.          cmul eax,ebx,ratiox
  256.          mov smatrix+0,eax
  257.  
  258.          if usez eq yes         ; if not using z rotation, ematrix+4 =0
  259.          mov ebx,ematrix+4
  260.          cmul eax,ebx,ratiox
  261.          mov smatrix+4,eax
  262.          endif
  263.  
  264.          mov ebx,ematrix+8
  265.          cmul eax,ebx,ratiox
  266.          mov smatrix+8,eax
  267.  
  268.          mov ebx,ematrix+12
  269.          cmul eax,ebx,ratioy
  270.          mov smatrix+12,eax
  271.  
  272.          mov ebx,ematrix+16
  273.          cmul eax,ebx,ratioy
  274.          mov smatrix+16,eax
  275.  
  276.          mov ebx,ematrix+20
  277.          cmul eax,ebx,ratioy
  278.          mov smatrix+20,eax
  279.  
  280.          ret
  281.  
  282. ; if perfect_stars = no, stars will not go  through  correct  3d  calculation
  283. ; but will be calculated 40% faster. you  must  set  the  values  xstar   and
  284. ; ystar  to 3d  quick  multipliers  so  this  matrix  calculation  makes  the
  285. ; stars "look" the same.  I did this by moving the camera around and  testing
  286. ; if the stars moved the same as the objects.  I did this because the objects
  287. ; go through the correct 3d calculation and this gave me a base by  which  to
  288. ; adjust these numbers.
  289.  
  290.          else
  291.  
  292. set_star_matrix:
  293.          mov ebx,ematrix+0
  294.          cmul eax,ebx,xstar
  295.          shr eax,2
  296.          mov smatrix+0,eax
  297.  
  298.          if usez eq yes         ; if not using z rotation, ematrix+4 =0
  299.          mov ebx,ematrix+4
  300.          cmul eax,ebx,xstar
  301.          shr eax,2
  302.          mov smatrix+4,eax
  303.          endif
  304.  
  305.          mov ebx,ematrix+8
  306.          cmul eax,ebx,xstar
  307.          shr eax,2
  308.          mov smatrix+8,eax
  309.  
  310.          mov ebx,ematrix+12
  311.          cmul eax,ebx,ystar
  312.          shr eax,2
  313.          mov smatrix+12,eax
  314.  
  315.          mov ebx,ematrix+16
  316.          cmul eax,ebx,ystar
  317.          shr eax,2
  318.          mov smatrix+16,eax
  319.  
  320.          mov ebx,ematrix+20
  321.          cmul eax,ebx,ystar
  322.          shr eax,2
  323.          mov smatrix+20,eax
  324.  
  325.          ret
  326.          endif
  327.  
  328. ; rotate star using smatrix (imported from math.inc)
  329.  
  330.          align 16
  331.  
  332. srotatex:
  333.          mov eax,smatrix+8
  334.          imul ebp
  335.          shrd eax,edx,14
  336.          mov edi,eax
  337.          if usez eq yes
  338.          mov eax,smatrix+4
  339.          imul ecx
  340.          shrd eax,edx,14
  341.          add edi,eax
  342.          endif
  343.          mov eax,smatrix+0
  344.          imul ebx
  345.          shrd eax,edx,14
  346.          add edi,eax   ; di = new x
  347.          ret
  348.  
  349.          align 16
  350.  
  351. srotatey:
  352.          mov eax,smatrix+16
  353.          imul ecx
  354.          shrd eax,edx,14
  355.          mov ecx,eax
  356.          mov eax,smatrix+20
  357.          imul ebp
  358.          shrd eax,edx,14
  359.          add ecx,eax
  360.          mov eax,smatrix+12
  361.          imul ebx
  362.          shrd eax,edx,14
  363.          add ecx,eax   ; cx = new y
  364.  
  365.          mov ebp,esi
  366.          mov ebx,edi
  367.          ret
  368.  
  369.          if perfect_stars eq yes
  370.          align 16
  371.  
  372. srotatez:
  373.          mov eax,ematrix+32
  374.          imul ebp
  375.          shrd eax,edx,14
  376.          mov esi,eax
  377.          mov eax,ematrix+28
  378.          imul ecx
  379.          shrd eax,edx,14
  380.          add esi,eax
  381.          mov eax,ematrix+24
  382.          imul ebx
  383.          shrd eax,edx,14
  384.          add esi,eax   ; si = new z
  385.  
  386.          ret
  387.          endif
  388.  
  389. code32   ends
  390.          end
  391.